package com.chrray.position.controller.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.chrray.position.domain.dto.DeleteParam;
import com.chrray.position.service.position.FdHomeAdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.chrray.position.domain.vo.FdHomeAdVO;
import com.chrray.position.domain.dto.search.FdHomeAdSearch;
import com.chrray.position.domain.dto.FdHomeAdDTO;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 首页广告配置表控制器
 *
 * @author wusiwee
 * @email wusiwee@163.com
 * @since 1.0.1 2024-08-07
 */
@RestController
@RequestMapping("/api/app/home-ad")
@Api(tags = "首页广告配置表")
@AllArgsConstructor
public class FdHomeAdController{

    private final FdHomeAdService fdHomeAdService;

    @GetMapping("/latest")
    @ApiOperation("首页广告")
    public R<FdHomeAdVO> latest(){
        return R.ok(fdHomeAdService.latestAd());
    }


    @GetMapping("/pageList")
    @ApiOperation("分页列表")
    @ApiResponses({
        @ApiResponse(code=200, message = "ok", response = FdHomeAdVO.class)
    })
    public R<IPage<FdHomeAdVO>> pageList(@Valid FdHomeAdSearch param){
        return R.ok(fdHomeAdService.pageList(param));
    }

    @GetMapping("/{id}")
    @ApiOperation("查询详情")
    @ApiResponses({
        @ApiResponse(code=200, message = "ok", response = FdHomeAdVO.class)
    })
    public R<FdHomeAdVO> get(@ApiParam(name = "id",value = "主键id",required = true) @PathVariable("id") Long id){
        return R.ok(fdHomeAdService.info(id));
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("新增编辑")
    public R<Boolean> saveOrUpdate(@RequestBody FdHomeAdDTO body){
        return R.ok(fdHomeAdService.saveOrUpdate(body));
    }

    @DeleteMapping("/remove")
    @ApiOperation("批量删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "idList", value = "主键数组")
    })
    public R<Boolean> delete(@RequestBody DeleteParam param){
        return R.ok(fdHomeAdService.delete(param.getIds()));
    }
}
